Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

234
Visualizações
How to use "oneOf" in this schema?

I'd like to have either A or B, but not both (mutual exclusive.)

I have to use whatever is avaliable in Draft 3, even though it says 4 on the top. Reason being, when using array for "required", it throws an error that it can't convert an array to a boolean. If I remove arrays without putting that I'm using draft 4 [Newtonsoft.Json.Schema.Extensions]::IsValid does not validate. It returns "true" willy nilly.

Yes, I have to use an obsolete Newtonsoft.

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "description": "",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "SearchCriteria": {
      "type": "array",
      "uniqueItems": true,
      "minItems": 1,
      "required": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "A": {
            "type": "string",
            "minLength": 1,
            "pattern": "^[^\\s]*$"
          },
          "B": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "pattern": "^[^\\s]*$",
              "enum": ["One", "Two"]
            },
            "minItems": 1
          },
          "C": {
            "type": "string",
            "required": true,
            "minLength": 2
          },
          "D": {
            "type": "array",
            "required": true,
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "uniqueItems": true
          }
        }
      }
    }
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Draft 3 does not support OneOf or any of the likes as @dbc mentioned in a comment.

[Newtonsoft.Json.Schema.JsonSchema] uses draft 3 to prase the JSON file. Hence why it was ignoring OneOf AND throwing an error for "required" being an array. In draft 3, "required" can only be a boolean.

To overcome this, use [Newtonsoft.Json.Schema.JSchema] to parse the Schema as a string and [Newtonsoft.Json.Linq.JToken] to parse the JSON as a string, and [Newtonsoft.Json.Schema.SchemaExtensions] to validate isntead of [Newtonsoft.Json.Schema.Extensions].

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda